package com.zch.book.dao.impl;

import java.sql.SQLException;

import com.zch.book.dao.UserDao;
import com.zch.book.entity.User;
import com.zch.book.util.DBUtil;

public class UserDaoImpl extends DBUtil implements UserDao {
	
		@Override
		public User getUserByName(String name) {
			//声明一个User对象
			User user=null;
			// 链接数据库验证用户名是否存在
			String sql="select * from user1 where user_name=?";
			Object[] params={name};
			executeQuery(sql, params);
			try {
				//循环输出rs
				while(rs.next()){
					//取密码
					String pwd=rs.getString(2);
					int role=rs.getInt(3);
					user=new User(name, pwd, role);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}finally{
				//关闭资源
				closeSource();
			}
			return user;
		}

	}
